<?php

namespace App\Http\Controllers;

use DB;
use Illuminate\Http\Request;
use Validator;


class UserSystemController extends Controller
{
    function show(Request $request, $uid){
        $input = $request->all();

        $systemIdHash = ["edu"=>1,"library"=>2];
        if(!empty($input["system_cat"]) && isset($systemIdHash[$input["system_cat"]]))
        	$systemCatId = $systemIdHash[$input["system_cat"]];

        $systemResult = DB::table("cp_user_system")
          ->select("cp_user_system.campus_id","cp_user_system.system_id","cp_system.name AS system_name")
          ->leftJoin("cp_system","cp_system.id","=","cp_user_system.system_id")
          ->where("cp_user_system.user_id",$uid)
          ->where("cp_user_system.password","!=","");
          
        if(isset($systemCatId))
          $systemResult = $systemResult->where("cp_system.cat_id",$systemCatId);
          
        $systemResult = $systemResult
          ->orderBy("cp_user_system.id","DESC")
          ->first();

        return $this::jsonResponse(false,$systemResult);
    }

}